package com.fare.taluo.application.impl.crawl.crawlstatistics;

import java.sql.Date;
import java.util.ArrayList;
import java.util.List;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.fare.taluo.application.crawl.crawlstatistics.FdcCrawlStatisticsForGrabDateApplication;
import com.fare.taluo.core.domain.crawl.FdcCrawlStatisticsForGrabDateEntity;
import com.fare.taluo.util.DateUtils;
import com.fare.taluo.vo.crawl.statistics.FdcCrawlStatisticsForGrabDateVo;
@Transactional
@Scope("singleton")
@Service("fdcCrawlStatisticsForGrabDateApplication")
public class FdcCrawlStatisticsForGrabDateApplicationImpl implements FdcCrawlStatisticsForGrabDateApplication{

	@Override
	public List<FdcCrawlStatisticsForGrabDateVo> findByGrabDate(String dateStr, String dateStr2) {
		List<FdcCrawlStatisticsForGrabDateVo> listVo=new ArrayList<FdcCrawlStatisticsForGrabDateVo>();
		FdcCrawlStatisticsForGrabDateEntity tp=new FdcCrawlStatisticsForGrabDateEntity();
		Date date1=null,date2=null;
		if(dateStr !=null && !dateStr.equals("") ){
			date1=new java.sql.Date((DateUtils.strToDate(dateStr,"yyyy-MM-dd")).getTime());
		}
		if(dateStr2!=null && !dateStr2.equals("")){
			date2=new java.sql.Date((DateUtils.strToDate(dateStr2,"yyyy-MM-dd")).getTime());
		}
		
		List<FdcCrawlStatisticsForGrabDateEntity> listEntity=tp.findByGrabDate(date1,date2,null);
		if(listEntity.size()>0){
			for(FdcCrawlStatisticsForGrabDateEntity entity:listEntity){
				FdcCrawlStatisticsForGrabDateVo vo=new FdcCrawlStatisticsForGrabDateVo();
				vo.setCreateTime(entity.getCreateTime());
				vo.setCreateTimeStr(null);
				vo.setDayLineNumbers(entity.getDayTotalLineNumbers());
				vo.setDaySourceDatas(entity.getDayTotalSourceData());
				vo.setGrabDate(entity.getGrabDate());
				vo.setGrabDateStr(entity.getGrabDate() !=null?DateUtils.dateToStr(new java.sql.Date(entity.getGrabDate().getTime()),"yyyy-MM-dd"):null );
				vo.setId(Long.parseLong(entity.getId()));
				vo.setSourceByChannel(entity.getSourceByChannel());
				vo.setLineByChannel(entity.getLineByChannel());
				
				listVo.add(vo);
			}
		}
		
		return listVo;
	}
	
}
